/*
 * TelaSweda.java
 *
 * Created on 5 de Setembro de 2008, 14:49
 */

package gui;

import javax.swing.JOptionPane;
import javax.swing.UIManager;

import test.SwedaTest;

/**
 *
 * @author  murilo
 */
public class TelaSweda extends javax.swing.JFrame {

	SwedaTest sw = new SwedaTest();


	/** Creates new form TelaSweda */
	public TelaSweda() {
		initComponents();
	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
	private void initComponents() {

		cpfText = new javax.swing.JTextField();
		jLabel1 = new javax.swing.JLabel();
		abrirCupomBT = new javax.swing.JButton();
		codigoText = new javax.swing.JTextField();
		descricaoText = new javax.swing.JTextField();
		valorUniText = new javax.swing.JTextField();
		quantidadeText = new javax.swing.JTextField();
		jLabel2 = new javax.swing.JLabel();
		jLabel3 = new javax.swing.JLabel();
		jLabel4 = new javax.swing.JLabel();
		jLabel5 = new javax.swing.JLabel();
		aliquotaText = new javax.swing.JTextField();
		jLabel6 = new javax.swing.JLabel();
		venderItemBT = new javax.swing.JButton();
		iniciarFechamentoBT = new javax.swing.JButton();
		especieText = new javax.swing.JTextField();
		valorEspecieText = new javax.swing.JTextField();
		jLabel7 = new javax.swing.JLabel();
		jLabel8 = new javax.swing.JLabel();
		efetuaPagamentoText = new javax.swing.JButton();
		mensagemText = new javax.swing.JTextField();
		jLabel9 = new javax.swing.JLabel();
		terminaFechamentoBT = new javax.swing.JButton();
		abrePortaBT = new javax.swing.JButton();
		fecharPortaBT = new javax.swing.JButton();
		LeituraXBT = new javax.swing.JButton();
		retornoBT = new javax.swing.JButton();
		cancelarCupomBT = new javax.swing.JButton();

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
		getContentPane().setLayout(null);
		getContentPane().add(cpfText);
		cpfText.setBounds(10, 30, 120, 20);

		jLabel1.setText("CPF");
		getContentPane().add(jLabel1);
		jLabel1.setBounds(10, 10, 19, 14);

		abrirCupomBT.setText("Abrir Cupom");
		abrirCupomBT.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				abrirCupomHandle(evt);
			}
		});
		getContentPane().add(abrirCupomBT);
		abrirCupomBT.setBounds(10, 60, 120, 23);

		codigoText.setText("123456789");
		getContentPane().add(codigoText);
		codigoText.setBounds(160, 30, 110, 20);

		descricaoText.setText("Tomate Vermelho");
		getContentPane().add(descricaoText);
		descricaoText.setBounds(160, 80, 140, 20);

		valorUniText.setText("1,45");
		getContentPane().add(valorUniText);
		valorUniText.setBounds(160, 130, 110, 20);

		quantidadeText.setText("1,532");
		getContentPane().add(quantidadeText);
		quantidadeText.setBounds(160, 180, 110, 20);

		jLabel2.setText("Codigo");
		getContentPane().add(jLabel2);
		jLabel2.setBounds(160, 10, 70, 14);

		jLabel3.setText("Descri\u00e7\u00e3o");
		getContentPane().add(jLabel3);
		jLabel3.setBounds(160, 60, 50, 14);

		jLabel4.setText("Valor Unit\u00e1rio");
		getContentPane().add(jLabel4);
		jLabel4.setBounds(160, 110, 80, 14);

		jLabel5.setText("Quantidade");
		getContentPane().add(jLabel5);
		jLabel5.setBounds(160, 160, 70, 14);

		aliquotaText.setText("II");
		getContentPane().add(aliquotaText);
		aliquotaText.setBounds(160, 230, 110, 20);

		jLabel6.setText("Aliquota");
		getContentPane().add(jLabel6);
		jLabel6.setBounds(160, 210, 90, 14);

		venderItemBT.setText("Vender Item");
		venderItemBT.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				venderItemHandle(evt);
			}
		});
		getContentPane().add(venderItemBT);
		venderItemBT.setBounds(160, 270, 105, 23);

		iniciarFechamentoBT.setText("Inicia Fechamento");
		iniciarFechamentoBT.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				iniciarFechamentoHandle(evt);
			}
		});
		getContentPane().add(iniciarFechamentoBT);
		iniciarFechamentoBT.setBounds(330, 10, 120, 23);

		especieText.setText("Dinheiro");
		getContentPane().add(especieText);
		especieText.setBounds(330, 60, 90, 20);

		valorEspecieText.setText("2,00");
		getContentPane().add(valorEspecieText);
		valorEspecieText.setBounds(430, 60, 110, 20);

		jLabel7.setText("Valor");
		getContentPane().add(jLabel7);
		jLabel7.setBounds(330, 40, 24, 14);

		jLabel8.setText("Especie");
		getContentPane().add(jLabel8);
		jLabel8.setBounds(430, 40, 60, 14);

		efetuaPagamentoText.setText("Efetua Pagamento");
		efetuaPagamentoText.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				efetuarPagamentoHandle(evt);
			}
		});
		getContentPane().add(efetuaPagamentoText);
		efetuaPagamentoText.setBounds(330, 90, 140, 23);

		mensagemText.setText("Volte Sempre");
		getContentPane().add(mensagemText);
		mensagemText.setBounds(330, 140, 140, 20);

		jLabel9.setText("Mensagem");
		getContentPane().add(jLabel9);
		jLabel9.setBounds(330, 120, 60, 14);

		terminaFechamentoBT.setText("Termina Fechamento");
		terminaFechamentoBT.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				terminaFechamentoHandle(evt);
			}
		});
		getContentPane().add(terminaFechamentoBT);
		terminaFechamentoBT.setBounds(330, 170, 140, 23);

		abrePortaBT.setText("Abrir Porta");
		abrePortaBT.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				abrirPortaHandle(evt);
			}
		});
		getContentPane().add(abrePortaBT);
		abrePortaBT.setBounds(10, 340, 105, 23);

		fecharPortaBT.setText("Fechar Porta");
		fecharPortaBT.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				fecharPortaHandle(evt);
			}
		});
		getContentPane().add(fecharPortaBT);
		fecharPortaBT.setBounds(140, 340, 105, 23);

		LeituraXBT.setText("Leitura X");
		LeituraXBT.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				leituraXHandle(evt);
			}
		});
		getContentPane().add(LeituraXBT);
		LeituraXBT.setBounds(310, 340, 105, 23);

		retornoBT.setText("Retornos");
		retornoBT.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				retornosHandle(evt);
			}
		});
		getContentPane().add(retornoBT);
		retornoBT.setBounds(440, 340, 77, 23);

		cancelarCupomBT.setText("CancelarCupom");
		cancelarCupomBT.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				cancelarCupomHandle(evt);
			}
		});
		getContentPane().add(cancelarCupomBT);
		cancelarCupomBT.setBounds(10, 100, 120, 23);

		java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
		setBounds((screenSize.width-572)/2, (screenSize.height-420)/2, 572, 420);
		setLocationRelativeTo(null);
	}// </editor-fold>//GEN-END:initComponents

	private void abrirPortaHandle(java.awt.event.ActionEvent evt) {
		try {
			sw.abrirPorta();
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this, e.getMessage());
			e.printStackTrace();
		}
	}

	private void fecharPortaHandle(java.awt.event.ActionEvent evt) {
		try{
			sw.fechaPorta();
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this, e.getMessage());
			e.printStackTrace();
		}
	}
	private void retornosHandle(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_retornosHandle
		try {
			JOptionPane.showMessageDialog(this, sw.retornos());
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this, e.getMessage());
			e.printStackTrace();
		}
	}//GEN-LAST:event_retornosHandle

	private void leituraXHandle(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_leituraXHandle
		try {
			sw.leituraX();
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this, e.getMessage());
			e.printStackTrace();
		}
	}//GEN-LAST:event_leituraXHandle

	private void terminaFechamentoHandle(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_terminaFechamentoHandle
		try {
			sw.terminaFechamento(mensagemText.getText());
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this, e.getMessage());
			e.printStackTrace();
		}
	}//GEN-LAST:event_terminaFechamentoHandle

	private void efetuarPagamentoHandle(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_efetuarPagamentoHandle
		try {
			sw.efetuaPagamento(especieText.getText(),valorEspecieText.getText());
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this, e.getMessage());
			e.printStackTrace();
		}
	}//GEN-LAST:event_efetuarPagamentoHandle

	private void iniciarFechamentoHandle(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_iniciarFechamentoHandle
		try {
			sw.iniciaFechamentoCupom();
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this, e.getMessage());
			e.printStackTrace();
		}
	}//GEN-LAST:event_iniciarFechamentoHandle

	private void venderItemHandle(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_venderItemHandle
		try {
			sw.venderItem(codigoText.getText(), descricaoText.getText(), 
					valorUniText.getText(), quantidadeText.getText(), aliquotaText.getText());
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this, e.getMessage());
			e.printStackTrace();
		}
	}//GEN-LAST:event_venderItemHandle

	private void cancelarCupomHandle(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelarCupomHandle
		try {
			sw.cancelaCupom();
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this, e.getMessage());
			e.printStackTrace();
		}
	}//GEN-LAST:event_cancelarCupomHandle

	private void abrirCupomHandle(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_abrirCupomHandle
		try {
			sw.abrirCupom(cpfText.getText());
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this, e.getMessage());
			e.printStackTrace();
		}
	}//GEN-LAST:event_abrirCupomHandle

	/**
	 * @param args the command line arguments
	 */
	public static void main(String args[]) {

		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (Exception e) {
			e.printStackTrace();
		}

		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new TelaSweda().setVisible(true);
			}
		});
	}

	// Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JButton LeituraXBT;
	private javax.swing.JButton abrePortaBT;
	private javax.swing.JButton abrirCupomBT;
	private javax.swing.JTextField aliquotaText;
	private javax.swing.JButton cancelarCupomBT;
	private javax.swing.JTextField codigoText;
	private javax.swing.JTextField cpfText;
	private javax.swing.JTextField descricaoText;
	private javax.swing.JButton efetuaPagamentoText;
	private javax.swing.JTextField valorEspecieText;
	private javax.swing.JButton fecharPortaBT;
	private javax.swing.JButton iniciarFechamentoBT;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JLabel jLabel2;
	private javax.swing.JLabel jLabel3;
	private javax.swing.JLabel jLabel4;
	private javax.swing.JLabel jLabel5;
	private javax.swing.JLabel jLabel6;
	private javax.swing.JLabel jLabel7;
	private javax.swing.JLabel jLabel8;
	private javax.swing.JLabel jLabel9;
	private javax.swing.JTextField mensagemText;
	private javax.swing.JTextField quantidadeText;
	private javax.swing.JButton retornoBT;
	private javax.swing.JButton terminaFechamentoBT;
	private javax.swing.JTextField especieText;
	private javax.swing.JTextField valorUniText;
	private javax.swing.JButton venderItemBT;
	// End of variables declaration//GEN-END:variables

}
